#include <stdio.h>
#include <stdlib.h>
#include <linklist.h>

linklist *init_list();
status destroy_list(linklist *L);
status clear_list(linklist *L);
status insfirst(link *h, link *s); //h is head node , insert s in first node before
status delfirst(link *h, link *q); // del first node;
status append(linklist *L, link *s); //append *s(and end) in L end;
status remove(linklist *L, link *q); // remove end node is tail , and change tail node;
status ins_before(linklist *L, link *p, link *s); //insert s before p node,ang change p->new;
status in_after(linklist *L, link *p, link *s);
status set_curelem(link *p, elemtype e);// updata p->data = e;
elemtype get_curelem(link *p); //return p->data;
status list_empty(linklist *L);
int list_length(linklist *L);
link *get_head(linklist *L);
link *get_last(linklist *L);
link *prior_pos(linklist *L, link *p); //return prior p node*;
link *next_pos(linklist *L, link *p); //return next p node*;else return null;

status locate_pos(linklist *L, int i, link *p);

link *locate_elem(linklist *L, elemtype e ,status (*compare)(elemtype, elemtype));// first e = elemtype node*
status list_traverse(linklist *L, status(*visit)());



/*  
linklist *init_list()
{
	linklist *L
	L = (linklist *)malloc(linklist);
	if(!L)
		return -1;
	L->next = NULL;
	return 0;

}

status destroy_list(linklist *L)
{
	linklist *p = L;
	while(L)
	{
		p = L->next;
		free(L);
		L = p; 			
	}
	if(!L)
		return 0;

}
status clear_list(linklist *L)
{
	if(!list_empty)
		return -2;
	linklist *p = L->next,q;
	while(p)
	{
		q = p;
		free(q);
		p = p->next;
	}
	L->next = NULL;
	return 0;


}

status list_empty(linklist *L)
{
	if(L->next == NULL)
		return 1;
	else
		return 0;
}
status list_length(linklist *L)
{
	int i;
	linklist *p = L;
	while(p)
	{
		p = p->next;
		i++;
	}
	return i;

}

status get_elem(linklist *L, int i, elemtype *e)
{
	if(i<1 || i>list_length(L))
		return -3;

	linklist *p = L->next;

	whlie(--i)
		p = p->next;

	*e = p->data;

	return 0;

}

status LocateElem(linklist *L, elemtype e, compare())
{
	if(!linklist_empty(L))
		return -1;

	int i=1;
	linklist *p = L->next;
	while(p)
	{
		if(compare(p->data,*e))
			return i;
		p = p->next;
		i++;	
	}
	
	if(!p)
		return -2;
			
}
status prior_elem(linklist *L, elemtype *cur_e, elemtype *pre_e)
{
    linklist *p,*q;	
}
status next_elem(linklist *L, elemtype cur_e, elemtype &next_e)
status list_insert(linklist *L, int i, elemtype e)
{
    if(!L->next)
        return -1;
    int j ;
    linklist *p.*q;
    p = L;
    while(p && j < i-1)
    {
        j++; 
        p = p->next;
    }
      
    q = (linklist *)malloc(sizeof(linklist));
    q->data = e;
    q->next = p->next;
    p->next = q;
    return 0;


}

status list_delete(linklist *L, int i, elemtype *e)
{
    if(!L->next)
        return -1;
    int j = 1;
    linklist *q,*p = *L;

    while(j<i && p)
    {
        p = p->next;
        j++;
    }

    if(p)
    {
        q = p->next;
        p->next = q->next;
        *e = q->data;
        free(q);
        return 0;
    }else
        return -1;

}
status list_traverse(linklist *L, visit())
*/
